package ntu.edu.cn.util;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by Morven Qiu on 8/9/2016.
 * to download verification code
 */
public class DownloadYZM {

    private static final Logger logger = Logger.getLogger(DownloadYZM.class);
    /**
     * get the inputstream for verification code
     * @param httpClient
     * @return
     * @throws Exception
     */
    public static InputStream downloadFile(CloseableHttpClient httpClient){
        InputStream inputStream = null;
        try{
            inputStream = httpClient.execute(new HttpGet("http://jwgl.ntu.edu.cn/cjcx/checkImage.aspx")).getEntity().getContent();
        }catch (IOException e){
            logger.error("error occurred when download the verification code");
        }
        return inputStream;
    }
}
